#coding=utf-8
#!/usr/bin/python

'''
Created on 2012-11-17

@author: Neo.Chen
'''

import ktlib
import httplib
import json

def SendErrorMessage(appName, message):
    str = "%s error! %s" % (appName, message)
    #发邮件通知
    ktlib.send_email("admin@sky-mobi.com", "neo.chen@sky-mobi.com", str, "rt")
    ktlib.send_email("admin@sky-mobi.com", "18758166494@139.com", str, "rt")
    ktlib.send_email("admin@sky-mobi.com", "tristan.yang@sky-mobi.com", str, "rt")
    ktlib.send_email("admin@sky-mobi.com", "13958110295@139.com", str, "rt")
    #写单独的日志文件
    ktlib.append_log("./%s_error.log" % (appName), str)


def getActiveRoom(urm_host, urm_port):
    roomids = []
    try:
        conn = httplib.HTTPConnection(urm_host)
        conn.request("GET", "/room!getRoomPop")
        r1 = conn.getresponse()
        print(r1.status, r1.reason)
        print(r1)
        data = r1.read()
        roominfo = data
        locations = json.loads(roominfo)
        for location in locations:
            status = location["status"]
            roomid = location["roomId"]
            roomName = location["roomName"]
            showerName = location["showerName"]
            if status == 2:
                print("roomid:%d, roomName:%s, showerNam:%s \r\n" % (roomid, roomName, showerName))
                roomids.append(roomid)
    except:
        print("connect urm error")
    return roomids

def main():
    print("main start...")
    roomids = []
    roomids = getActiveRoom("www.52le.com", 80)
    print(roomids)

if __name__ == '__main__':
    main()



















